// 映射工具类
const MapUtils = {
  roomMap: {},   // 房间ID -> roomNumber 映射
  seatMap: {},    // 座位ID -> seatNumber 映射
  dishMap: {},    // 菜品ID -> name 映射

  // 设置房间映射
  setRoomMap(roomList) {
    this.roomMap = {};
    roomList.forEach(room => {
      this.roomMap[room.id] = room.roomNumber;
    });
  },

  // 设置座位映射
  setSeatMap(seatList) {
    this.seatMap = {};
    seatList.forEach(seat => {
      this.seatMap[seat.id] = seat.seatNumber;
    });
  },
  // 设置菜品映射
  setDishMap(dishList) {
    this.dishMap = {};
    dishList.forEach(dish => {
      this.dishMap[dish.id] = dish.name;
    });
  },

  // 获取房间号
  getRoomNumber(id) {
    return this.roomMap[id] || id; // 找不到映射时返回原始ID
  },

  // 获取座位号
  getSeatNumber(id) {
    return this.seatMap[id] || id; // 找不到映射时返回原始ID
  },
  // 获取菜品名字
  getDishNumber(id) {
    return this.dishMap[id] || id; // 找不到映射时返回原始ID
  },
  // 判断三种映射是否都为空
  isEmpty() {
    // 检查对象是否没有任何可枚举属性
    const isRoomEmpty = Object.keys(this.roomMap).length === 0;
    const isSeatEmpty = Object.keys(this.seatMap).length === 0;
    const isDishEmpty = Object.keys(this.dishMap).length === 0;
    
    // 输出各映射的空状态
    // console.log(`房间映射${isRoomEmpty ? '为空' : '不为空'}`);
    // console.log(`座位映射${isSeatEmpty ? '为空' : '不为空'}`);
    // console.log(`菜品映射${isDishEmpty ? '为空' : '不为空'}`);
    
    // 当有映射为空时才返回true
    return {isRoomEmpty , isSeatEmpty , isDishEmpty}
  }
};

export default MapUtils;